/************************************************************************/
/*  									*/
/*  perturb_MSE.c							*/
/*									*/
/*  Tom Lookabaugh							*/
/*  August 13, 1987							*/
/*  Last Revision: August 14, 1987					*/
/*									*/
/*  DESCRIPTION								*/
/*	Mean square error version.  If magnitude is less than		*/
/*	0.9*add_off, perturb by a fixed amount; otherwise, perturb	*/
/* 	by a multiple of the original value.				*/
/*  RETURNS								*/
/*	No significant value.  Modifies storage pointed to by target.	*/
/*  CALLS								*/
/*	none.								*/
/*									*/
/************************************************************************/

#include "stdvq.h"
#include <math.h>

perturb (source, target, add_off, mult_off)

    double *source;	/* source vector (to be perturbed)		*/
    double *target;	/* target vector 				*/
    double add_off;	/* additive offset				*/
    double mult_off;	/* multiplicative offset			*/

{
    int  d;		/* iteration counter				*/
    double mag;		/* magnitude of perturbation			*/

    for (d = 0; d < dim; d++) {
       if (source[d] == 0.0)
	    mag = add_off;
	  else
	    mag = (fabs(source[d]) < 0.9*add_off) ? 
		add_off*fabs(source[d])/source[d]:
		(double) mult_off*source[d];
	target[d] = source[d] + mag*((double) rand())/2147483647.0;
    }

}
